package com.ruoyi.list.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.list.domain.HospitalDeviceList;
import com.ruoyi.list.service.IHospitalDeviceListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 医院设备清单Controller
 *
 * @author zjt
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/list/list")
public class HospitalDeviceListController extends BaseController {
    @Autowired
    private IHospitalDeviceListService hospitalDeviceListService;

    /**
     * 查询医院设备清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(HospitalDeviceList hospitalDeviceList) {
        startPage();
        List<HospitalDeviceList> list = hospitalDeviceListService.selectHospitalDeviceListList(hospitalDeviceList);
        return getDataTable(list);
    }

    /**
     * 导出医院设备清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:list:export')")
    @Log(title = "医院设备清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalDeviceList hospitalDeviceList) {
        List<HospitalDeviceList> list = hospitalDeviceListService.selectHospitalDeviceListList(hospitalDeviceList);
        ExcelUtil<HospitalDeviceList> util = new ExcelUtil<HospitalDeviceList>(HospitalDeviceList.class);
        util.exportExcel(response, list, "医院设备清单数据");
    }

    /**
     * 获取医院设备清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('list:list:query')")
    @GetMapping(value = "/{listId}")
    public AjaxResult getInfo(@PathVariable("listId") Integer listId) {
        return success(hospitalDeviceListService.selectHospitalDeviceListByListId(listId));
    }

    /**
     * 新增医院设备清单
     */
    @PreAuthorize("@ss.hasPermi('list:list:add')")
    @Log(title = "医院设备清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalDeviceList hospitalDeviceList) {
        return toAjax(hospitalDeviceListService.insertHospitalDeviceList(hospitalDeviceList));
    }

    /**
     * 修改医院设备清单
     */
    @PreAuthorize("@ss.hasPermi('list:list:edit')")
    @Log(title = "医院设备清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalDeviceList hospitalDeviceList) {
        return toAjax(hospitalDeviceListService.updateHospitalDeviceList(hospitalDeviceList));
    }

    /**
     * 删除医院设备清单
     */
    @PreAuthorize("@ss.hasPermi('list:list:remove')")
    @Log(title = "医院设备清单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{listIds}")
    public AjaxResult remove(@PathVariable Integer[] listIds) {
        return toAjax(hospitalDeviceListService.deleteHospitalDeviceListByListIds(listIds));
    }
}
